#include <clutter/clutter.h>
#include <stdlib.h>

#define UNUSED(x) (void)x 

/* 这是Callback函数 */ 
static gboolean on_stage_button_press (ClutterStage *stage, ClutterEvent *event, gpointer data)
{
    float x = 0;
    float y = 0;
    UNUSED(stage);
    UNUSED(data);
    clutter_event_get_coords (event, &x, &y);

    g_print ("Event: %d(%s) , Stage clicked at (%f, %f) \n", event->type, 
     event->type==CLUTTER_BUTTON_PRESS ? "CLUTTER_BUTTON_PRESS" : "", x, y);

    return TRUE; /* Stop further handling of this event. */ 
}


int main(int argc, char * argv[])
{
    /*最后一个参数表示alpha参数，前面三个一次是红绿蓝。 */ 
    ClutterColor stage_color ={0x00,0x00,0x00,0x0f};

    /* 这是Clutter的初始化，在使用Clutter之前，必须调用此函数*/ 
    if( clutter_init(&argc, &argv) < 0 )
    {
        perror("clutter_init err:");
        return -1;
    }

    /* 所有的Clutter应用都至少包含一个ClutterStage。Stage含有的Actors例如rectangles,images,text。*/ 
    /* Get the stage and set its size and color*/ 
    ClutterActor * stage = clutter_stage_new ();
    clutter_actor_set_size (stage, 200, 200);
    clutter_actor_set_background_color (stage, &stage_color);
    /* quit on destroy */
    g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);

    /* 下面函数用于显示stage,Show the stage: */ 
    clutter_actor_show (stage);

    /* 下面函数不是Clutter的函数，是gtk的函数 。可以在GTK+2.0教程中找到相关的GtkWidget定义 */
    /* Connect a signal handler to handle mouse clicks an key presses on the stage: */ 
    g_signal_connect (stage, "button-press-event",G_CALLBACK (on_stage_button_press), NULL);

    /* 主循环，不会结束main。Start the main loop, so we can respond to events: */ 
    clutter_main();

    return EXIT_SUCCESS;
}